package com.keqing.controller;

import com.ganyu.domain.ResponseResult;
import com.ganyu.domain.dto.AddArticleDto;
import com.ganyu.domain.dto.UpdateAdminArticleDto;
import com.ganyu.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/content/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @PreAuthorize("@ps.hasPermission()")
    @PostMapping
    public ResponseResult add(@RequestBody AddArticleDto article){
        return articleService.add(article);
    }

    //文章模糊查询
    @GetMapping("/list")
    public ResponseResult getArticleFuzzy(Integer pageNum,Integer pageSize,String title,String summary){
        return articleService.getArticleFuzzy(pageNum, pageSize, title, summary);
    }
    //根据id查询文章
    @GetMapping("/{id}")
    public ResponseResult getArticleById(@PathVariable("id") Long id){
        return articleService.getArticleById(id);
    }

    @PreAuthorize("@ps.hasPermission()")
    @PutMapping
    public ResponseResult updateArticle(@RequestBody UpdateAdminArticleDto updateAdminArticleDto){
        return articleService.updateArticle(updateAdminArticleDto);
    }
    @PreAuthorize("@ps.hasPermission()")
    @DeleteMapping("/{id}")
    public ResponseResult deleteArticle(@PathVariable("id") Long[] ids){
        return articleService.deleteArticle(ids);
    }
}